/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Open New Window, and at the same time, re-direct Parent Window

Hi,

I thought I wouldn’t have to ask this silly question on a forum ?

But, I can’t seem to find the solution anywhere.

I have a JavaScript that opens a new window when a button is clicked.

It works fine. But, I want to [B]re-direct the Parent Window[/B] (current page) once the new window is opened.

Here is my script :

[CODE]<script type=”text/javascript”>
function OpenWindow() {
window.open (‘/My_Folder/file.php’, ‘newwindow’, config=’height=670, width=1400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no’);
}
</script>[/CODE]

And, of course the button :

[code=html]<input type=”button” value=”Submit” onclick=”OpenWindow()”>[/code]

So, in order to be able to re-direct the Parent Window, after the new window has popped up, I added a simple line to my JS function :

[CODE]<script type=”text/javascript”>
function OpenWindow() {
window.open (‘/My_Folder/new_file.php’, ‘newwindow’, config=’height=670, width=1400,
toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no’);
}

setTimeout(1000, ‘/My_Folder/PHP/file_2.php’);

</script>[/CODE]

Meaning, after the new window has popped up, the Parent Window should [B]re-direct in 1 second.[/B]

But, for some reason, it’s not working.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@Kevin2May 01.2015 — Try this:
&lt;script&gt;
function OpenWindow() {
window.open ('/My_Folder/new_file.php', 'newwindow', 'height=670, width=1400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');

<i> </i> window.location = '/My_Folder/PHP/file_2.php';
<i> </i>}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@newuserphpauthorMay 02.2015 — Try this:
&lt;script&gt;
function OpenWindow() {
window.open ('/My_Folder/new_file.php', 'newwindow', 'height=670, width=1400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');

<i> </i> window.location = '/My_Folder/PHP/file_2.php';
<i> </i>}
&lt;/script&gt;
[/QUOTE]



Thanks Kevin. But, your code gave me a syntax error.

Shouldn't there be brackets and a semi-colon somewhere enclosing this : [B]window.location = '/My_Folder/PHP/file_2.php';[/B] ??

No idea what the syntax error is, as Eclipse wouldn't explain it. It simple indicates that something is missing (or should be removed)
Copy linkTweet thisAlerts:
@newuserphpauthorMay 02.2015 — So far, I've tried these 3 ways :

(a) <script type="text/javascript">

function OpenWindow() {

window.open ('/My_Folder/new_file.php', 'newwindow',

config='height=670, width=1400,


toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no,

directories=no, status=no');

window.top.location.href = '/My_Folder/PHP/file_2.php'

}


</script>[/QUOTE]



(b) <script type="text/javascript">

function OpenWindow() { window.open('/My_Folder/file.php','newwindow',

config='height=670,width=1400,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no');

settimeout( function(){document.location='/My_Folder/PHP/file_2.php'}, 1000 );

}

</script>
[/QUOTE]


(c) <script>

function OpenWindow() {

window.open ('/My_Folder/new_file.php', 'newwindow', 'height=670, width=1400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');

window.location = '/My_Folder/PHP/file_2.php';
}

</script>[/QUOTE]



Of all these, none are working.

But (b) is the best solution so far, because, at least, [B]it opens the New (Child) Window[/B], as it should. But, it still does not re-direct the Parent Window ?((
Copy linkTweet thisAlerts:
@ginerjmMay 02.2015 — Going back to you initial post, what is supposed to trigger the submit to redirect your parent window? Not that 'button' element?
Copy linkTweet thisAlerts:
@Kevin2May 02.2015 — Thanks Kevin. But, your code gave me a syntax error.[/QUOTE]

Don't know what to tell you. This works locally with a couple of random files. One opens in the new window the other opens in the parent. No syntax errors in any browser.

[code=html]<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>redirect</title>

<script>
function OpenWindow() {
window.open ('file1.htm', 'newwindow', 'height=670, width=1400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');

window.location = 'file2.htm';
}
</script>
</head>
<body>

<button onclick="OpenWindow()">Click</button>

</body>
</html>[/code]
Copy linkTweet thisAlerts:
@newuserphpauthorMay 02.2015 — Don't know what to tell you. This works locally with a couple of random files. One opens in the new window the other opens in the parent. No syntax errors in any browser.

[code=html]<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>redirect</title>

<script>
function OpenWindow() {
window.open ('file1.htm', 'newwindow', 'height=670, width=1400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');

window.location = 'file2.htm';
}
</script>
</head>
<body>

<button onclick="OpenWindow()">Click</button>

</body>
</html>[/code]
[/QUOTE]


Now it works!

Thanks ?
Copy linkTweet thisAlerts:
@Kevin2May 02.2015 — Now it works![/QUOTE]

Out of curiosity -- Why? The script is [I]exactly the same[/I] as the one I originally posted and which gave you "a syntax error".
×

Success!

Help @newuserphp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...