parent.location在Firefox和Chrome中不起作用,但在IE6中工作

时间:2022-12-06 19:21:29

JSP Problem:

<A NAME="CustomerInformation"></A>
<table class="SectionHeader1">
    <TBODY>enter code here
        <tr>
            <td>Customer Information</td>
        </tr>
    </TBODY>
</table>
<INPUT type="button" value="Customer Details" class="buttonSuper" 
       onmouseover="onMouseOverButton(this)" onmouseout="onMouseOutButton(this)" 
       name="customerDetails" style="" 
       onclick="parent.location='#CustomerInformation'">

This code is working on IE6 but not working in Chrome or Firefox. Onclick I'm trying to go on same window. Could you please suggest what is problem?

此代码适用于IE6,但无法在Chrome或Firefox中运行。 Onclick我正试着去同一个窗口。你能告诉我什么是问题吗?

2 个解决方案

#1


0  

If this is a pop-up, thr opener.location instead of parent.location. If this is from an Iframe and the parent is on a different domain, it will not work due to the Same Origin Policy.

如果这是一个弹出窗口,则使用thr opener.location而不是parent.location。如果这是来自Iframe且父级位于不同的域上,则由于同源策略而无法工作。

This is unclear in your question.

你的问题不清楚。

#2


0  

Your question is a bit unclear, as is your code. My interpretation was that you want a button that, when clicked, jumps to the Customer Details located on the same parent page. If that is the case, you can simplify your code. I wrote a sample that has a button element and jumps down to a Customer Information table. Some things to note:

您的问题有点不清楚,您的代码也是如此。我的解释是,您需要一个按钮,当单击该按钮时,会跳转到位于同一父页面上的“客户详细信息”。如果是这种情况,您可以简化代码。我写了一个包含按钮元素的示例,然后跳转到Customer Information表。有些事情需要注意:

  1. You don't NEED to do input="button", just works fine - but this code would work for as well.

    你不需要输入=“按钮”,只是工作正常 - 但这段代码也适用。

  2. If you want your current window to change its location, you can use javascript: window.location = {link here}; however, in this case you can simply just add a link tag around the button element.

    如果您希望当前窗口更改其位置,可以使用javascript:window.location = {link here};但是,在这种情况下,您只需在按钮元素周围添加一个链接标记即可。

  3. I added a tag around your table simply to add space between the button and the table; that way, you can see a jump in the page when the button is clicked.

    我在桌子周围添加了一个标签,只是为了在按钮和桌子之间增加空间;这样,单击按钮时,您可以看到页面中的跳转。

Code:

<!DOCTYPE html><html>
<head></head>
<body>
    <a href="#CustomerInformation"><button>Customer Details</button></a>

    <div style="padding-top:2500px;">
        <A NAME="CustomerInformation"></A>
        <table class="SectionHeader1">
        <TBODY>enter code here
        <tr>
            <td>Customer Information</td>
        </tr>
        </TBODY>
        </table>
    </div>
</body>
</html>

#1


0  

If this is a pop-up, thr opener.location instead of parent.location. If this is from an Iframe and the parent is on a different domain, it will not work due to the Same Origin Policy.

如果这是一个弹出窗口,则使用thr opener.location而不是parent.location。如果这是来自Iframe且父级位于不同的域上,则由于同源策略而无法工作。

This is unclear in your question.

你的问题不清楚。

#2


0  

Your question is a bit unclear, as is your code. My interpretation was that you want a button that, when clicked, jumps to the Customer Details located on the same parent page. If that is the case, you can simplify your code. I wrote a sample that has a button element and jumps down to a Customer Information table. Some things to note:

您的问题有点不清楚,您的代码也是如此。我的解释是,您需要一个按钮,当单击该按钮时,会跳转到位于同一父页面上的“客户详细信息”。如果是这种情况,您可以简化代码。我写了一个包含按钮元素的示例,然后跳转到Customer Information表。有些事情需要注意:

  1. You don't NEED to do input="button", just works fine - but this code would work for as well.

    你不需要输入=“按钮”,只是工作正常 - 但这段代码也适用。

  2. If you want your current window to change its location, you can use javascript: window.location = {link here}; however, in this case you can simply just add a link tag around the button element.

    如果您希望当前窗口更改其位置,可以使用javascript:window.location = {link here};但是,在这种情况下,您只需在按钮元素周围添加一个链接标记即可。

  3. I added a tag around your table simply to add space between the button and the table; that way, you can see a jump in the page when the button is clicked.

    我在桌子周围添加了一个标签,只是为了在按钮和桌子之间增加空间;这样,单击按钮时,您可以看到页面中的跳转。

Code:

<!DOCTYPE html><html>
<head></head>
<body>
    <a href="#CustomerInformation"><button>Customer Details</button></a>

    <div style="padding-top:2500px;">
        <A NAME="CustomerInformation"></A>
        <table class="SectionHeader1">
        <TBODY>enter code here
        <tr>
            <td>Customer Information</td>
        </tr>
        </TBODY>
        </table>
    </div>
</body>
</html>