The best way I can describe it is when on retailmenot, you click a link and it opens a new window containing the information but in the previous window it loads a new url...is there a way to do it in php? Thanks
You can set the variables within the link for example: http://example.com?varilable=2&variable=3 . So the 2 and 3 variable will be set within the php script. like $2=2 and $3=3 .When someone clich those link it will forward some information to other website. So it will redirect from your existing website to a new url will all variables set.
You will have to use javascripts window.location. So call a function with onclick and fist open the new window to the user and then call window.location. PHP will only redirect before headers are sent.
Thanks guys, but is there a way to do it with a form? Checking the retailmenot site they use a form to submit > then opens a window > redirects a current page to the company site.
Yea, you will still have to use javascript, the best way would be to open a new window and redirect onsubmit.
<script> function openInNewTabAndRedirect() { window.open("http://test.com", "test", "height=500,width=500"); // Open in a a new tab window.location.href = "http://website.com"; // Redirect to this webpage } </script> <button onclick="javascript:openInNewTabAndRedirect();" id="action">Open a new window and redirect the current one</button> Code (markup): Here is a script that I quickly put together. It will first open a new window and then redirect the current window.
Thanks everyone. I set this as best answer, but have a quick question - would this work with JS turned off or on IE7 or lower? Would this work the same if it was in a form submit button?
This would not work with Javascript turned off. Unfortunately, there is not a way to get this done without Javascript, but it should however work with IE 7 (as long as JS is enabled) or lower as the code is very primitive. It would work in the same way if it was called from a form submit button. Simply cut the <script> to the top of the page and add onclick="javascript:openInNewTabAndRedirect();" Code (markup): to the submit button. For example: <input type="submit"> Code (markup): Would be changed to: <input type="submit" onclick="javascript:openInNewTabAndRedirect();"> Code (markup):
Personally I wouldn't do it via Javascript, but with HTML/PHP instead. A form with a _blank target should give you the new window effect. Then have PHP redirect via headers to where you want to go.
I sort of think you're right so the submit would _blank and change current new window - but how to do in PHP?
Personally given that it's usability and accessibility crap, I wouldn't be shoving new windows down the user's throat in the first blasted place; you know, 80%+ of why the target attribute was deprecated in STRICT sixteen years ago? Using scripting to replicate an already frowned upon behavior is even worse, as it's completely missing the point. User wants a new window, let them choose that (middle-click, control-click) instead of removing that choice. EVERY time a website does that it just pisses me off.
Well... in certain cases it's okay to not having to ctrl-click - for Google-search, for instance, or for pages with repeat items that you want to look at - picture galleries, stores, etc. To me, having it default open in a new tab is a good thing. I do however agree - normally there's no reason for forcing this on users.
I was going to label it to notify users that it opens a new window, I'm basing it on the retailmenot model which when you click on a coupon, the current window changes to the destination and the new window opens up with a retailmenot site.
I have no clue what "retailmenot" is, but what you describe is EXACTLY the type of bullshit that makes me as a user of websites automatically navigate away from site that pull such stupid inaccessible painfully unusable "gee ain't it neat" script-tard stunts -- and a hefty part of why at this point I have little more than a giant middle finger for the entire web development community as a whole. I click on a **** coupon I want to go to the **** coupon, not have some other scam artist bullshit open in a new window! Sorry, MAJOR pet peeve when it comes to usability. Things like what you describe are EXACTLY the type of thing that makes me whip up the knife-hand ready to deliver a pimp slap to other developers.
It is pretty simple, you need to somehow communicate the link between Javascript and PHP (for example, if you send PHP #1 it should redirect to google.com, if you send it #2 it redirects to yahoo.com). Redirection in PHP is not hard at all, look at this link: http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php