I created a redirect function to redirect page when user submits input to the search box. When user search something, it will redirect to some webpage.
Let's say that redirected url is "http://www.google.com" (In real, I used different URL to redirect, but just picked google.com for example)
and below is what I created.
<script>
function redirect(){
window.location = "http://www.google.com";
return false;
}
</script>
The question is----
How can I be able to run another JavaScript <script>alert("hi")</script> when http://www.google.com webpage is successfully loaded?
I'm very new to JavaScript and HTML code, so any advise would be appreciated!
Unfortunately this is not possible. After redirecting to another page, you are not able to perform any actions on it, because you don't own this page and have no permissions to do so (except you are also the owner of the other page). This is similar to iFrames. You cannot access the foreign page, because then you could manipulate it and change it's content.
In your case the only action you could perform is, to show a dialog right before redirecting to another page.
Related
I have been searching in a lot of places for answer to this.
What I want is when I go on a page, it redirects the page to the password page, but when I try to get it back, it just redirects back onto the previous page. Maybe use javascript to say "only redirect when there is a part in that code? Any ideas?
http://sequoiapacificmortgage.com/loan-application/
I have embedded the clients' loan application form (on another website) into an iFrame so the user stays on the site. The loan application (upon submit) redirects to the client's Home Page, but unfortunately, it stays within the frame rather than going to the main Home Page window. I had inquired here about how to remedy this, and was told that the Target attribute target="_top" would do the trick.
The loan application processor people have no way to add the Target attribute to the redirect URL, and they have suggested the following:
"The thank you page after the application and before the redirect URL has a unique URL.
Is it possible to code your iframe to recognize this URL and redirect the full site to your home page rather than depending on the vLender redirect within the iframe?
I am including the unique thank you page URL from Lori's website below, the ref_ID attribute is the unique application ID number assigned to my test application (the application ID's are generated using the first 3 letters of the applicant's first name [LYN for Lynsee] and the first 3 letters of the applicant's last name [TES for Testing] followed by the numeric sequence) but you should be able to remove that and have your custom site's code recognize the .php url which would trigger a redirect within your site's code that would take place before our system enacts its redirect to the home page within the iframe.
(https://www.vlender.com/apps/templates/new_thank_you.php?ref_id=LYNTES998262971)"
Is it even possible to do this? Thanks for your advice!
regards, Ned
EDIT:
You could handle the navigation of the iframe, and see what url it goes to.
use onload to see when the iframe navigated to a new page, and contentWindow.location.href to get the url from the iframe.
something like:
function checkURL() {
if(document.getElementById('iframeID').contentWindow.location.href == "UNIQUE_URL") // if the location of the iframe is the unique url
window.location = "redirect.html"; //redirect this page somewhere else.
});
<iframe id="iframeID" onload="checkURL();" ... //onload fires when a page loads in the iframe
on load: http://w3schools.com/jsref/event_frame_onload.asp
get iframe URL:
Get current URL from IFRAME
I have visitors entering a certain PHP landing page, which has a link to an external website.
I want to track whether each visitor clicked that link, and receive additional info such as what was the HTTP referrer of it, entry time, clicking time, visit duration, browser etc.
One option that covers only tracking the HTTP referrer (actually, it would show me the "clean" search term that the visitor used to get to my website) is to use a piece of JavaScript code, which was generated by an automatic tool that my traffic source offers.
Since I'm sending the visitors to an external website, I suppose that the only way to have such a tracking, would be to send first anyone who clicks on the link, to an auto redirect page on my site that would contain this code.
Now, Assuming all my assumptions are correct (if not, please advise):
1) What other options do I have, besides using this automatic generated code?
2) Should such a redirect page be a PHP page?
3) In such a PHP page, I've read that it would be best to use:
header('Refresh: 3;url=http://www.external-page.com');
4) I assume 3 seconds are enough for the JavaScript code to fully work, Is there a way to display the visitor a dynamic countdown message?
5) I want the external website to open in a new browser window, is there a way with PHP to open such a window that would not contain any toolbars, and to have this window open up at a certain size (not the whole screen like with a "_blank" target)? if not, how do I do this with Javascript? does it involove a plugin?
6) What If I have to transform multiple landing pages to work in this way? should I manually create an individual redirect page for each landing page, or is there a way to make a template, that would receive the link input from the original page? maybe sending the user to a
redirect.php?link=http://link1.com
and then "GET" the link and echo it in the url, but It doesn't seem to be clean enough, I prefer that the user would not see such a messy destination url when he points on the link.
Thanks!
Just add a click event listener on your links and redirect directly to the remote site on success (assuming you are using jquery) :
$(document).ready(function() {
$('a').on('click', function(){
var href = $(this).attr('href');
// Send a transparent POST request to your server
$.post(
'/tracking-url',
{
url: href // you will have access to $_POST['url'] containing your href attribute value
},
function(response) {
// On success event
// If everything is ok (server-side), just redirect the user to the site
window.location = href;
}
).fail(function() {
// something unexpected occured
alert("error");
});
return false; // prevents the default event behaviour
});
});
And leave the link as it was :
Go to link1
See jQuery.post()
You can also use jQuery.get() to access a $_GET[] value.
I'm developing an app using Phonegap, the problem is when I go to a page it changes the URL but doesn't load the page. It refreshes the page and put the user back on the same page where he was.
Default URL:
localhost/pg_proj/www/index.html#gameDashboardPage
User Clicks on a link to go to the below URL
localhost/pg_proj/www/index.html#pendingChallengesPage
In the address bar, it changes the URL from #gameDashboardPage to #pendingChallengesPage but it doesn't load the #pendingChallengesPage page, instead it just refreshes the page and put the user back on #gameDashboardPage
Any suggestions will be great thanks
If I understood it correctly, it's not just refreshing the page. Your code on #pendingChallengesPage might contain code that redirects again back to it's previous. Please mention it, Is the URL is persist after reload? You've clearly stated that page content is not changing. What about the URL?
1) If you are redirecting inside a function twice, return; the function after it's first redirection.
2) Use event.preventDefault(); if necessary.
Reply with some more details. if you could, throw few script here.
You can add onclick and try event.preventDefault().
I'm using colorbox to "pop up" user profile when someone clicks on the profile link. The profile is loaded in iframe, because I would like them to be able to click couple of links inside and keep it in same popup. The problem occurs when user's session has timed out, because if the popup is opened it shows login page within the popup.
I'm wondering what I can do to control "outer" page based on what is returned in colorbox iframe. I'd like to redirect the entire page to login page not just the content of colorbox iframe. Is there a way to do this with javascript?
Please let me know if I did not describe the problem well enough.
Just paste this inside the <header> of your login page:
<script type="text/javascript">
if (window!=window.top) { window.top.location.href = window.location.href; }
</script>
This way you can show any page inside an iframe, except for the login page, wich will replace the entire page.
The script detects if the page is being loaded in the main window or inside an iframe, then perform a redirection to "escape" from the iframe.
you should use the following statement to redirect opening page.
window.opener.document.location.href= "/login";
If you are using ajax to load the content of iframe, than you can easily use this statement on the basis of ajax response. If you are not using ajax, than you have to send following response.
<script type="text/javascript">
window.opener.document.location.href= "/login";
</script>