How to change web-page without link? - greasemonkey

How to change web-page without link, using greasemonkey? Is it even possible? For e.g. , I am on http://www.google.com/ and how can I get to http://www.youtube.com without a link?

// ==UserScript==
// #name _Redirect foo.
// #include http://www.google.com/
// ==/UserScript==
//--- Do it this way to keep Google in history (back button).
window.location.href = 'http://www.youtube.com/';
//--- Or, do it this way to keep Google out of history.
window.location.replace ('http://www.youtube.com/');

Use the redirect:
Put this HTML redirect code between and tags of your HTML code.
< meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html">
source: http://www.web-source.net/html_redirect.htm
content is the number of seconds.
Here's an example where it refeshes the page: http://www.adelazzam.com/as.html

Related

Using # in landing page url

I'm using mysite.com/#contact as a landing page URL in some of the PPC campaigns, but when Google or Bing ads their URL parameters, I get url like mysite.com/#contact?campaign=x&source=x.. and the browser doesn't scroll down to the #contact anchor.
Any way to fix this? Or do I need to use a different URL?
In order to scroll down to the anchor it has to be at the very end of your url mysite.com?campaighn=x&source=x[...]#contact
I never used PPC ads so I don't know how to fix it, but at least that's the issue.
You could try to detect the URL parameter and use JavaScript to scroll to the specific location if true.
Untested combination of PHP / JS:
<?php if ( isset( $_GET['campaign'] ) { ?>
<script type="text/javascript">
//JS stuff
</script>
<?php } ?>

ModX redirect based on query string (Revolution 2.3)

I am rebuilding a website in ModX and I want to redirect the old URLs to the new ModX pages, automatically.
An old URL is of the form, http://www.oldsite.com/?pg=2
Every page is like this, so I need to manually map the old page IDs to the new ModX resource IDs. For example, pg=2 is the contact page, which is now resource ID 11, so I'll end up with a map like [2=>11, 3=>15, etc]
If I tweak the main index.php right in the docroot, this does exactly what I want:
/* execute the request handler */
if (!MODX_API_MODE) {
if (isset($_GET["pg"])) {
if ($_GET["pg"] == 2) {
$url = $url = $modx->makeUrl(11);
$modx->sendRedirect($url);
}
else {
// Page is set, but we don't have a redirect for it.
$modx->handleRequest();
}
}
else {
$modx->handleRequest();
}
}
However, I am not happy with hacking index.php directly. I'm a bit short of ModX experience to know exactly where to put this code. I tried:
A snippet, which I then called from my HTML header before any HTML, but the redirect stopped working
The Redirector extra, but this doesn't work on the QUERY_STRING, I don't think
Any insight is appreciated, for the best place to package this code, or a pointer towards an Extra I should be using.
The solution that worked for me, following Sean's insights below, is a plugin. The plugin code is below. For other plugin newbies like me, ensure you visit the "System Events" tab to enable your plugin for the event you're trying to access.
<?php
if ($modx->event->name == 'OnWebPageInit') {
// Look to see if the GET params include a pg. If they do, we have a request
// for one of the old pages.
if (isset($_GET["pg"])) {
// Map the old pg IDs to the new resource IDs.
if ($_GET["pg"] == 2) {
$url = $modx->makeUrl(11);
}
// Add more here...
// When done trying to match, redirect.
// But only do the redirect if we found a URL.
if (isset($url)) {
$modx->sendRedirect($url, array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
exit;
}
}
}
My preference to do this is in the .htaccess file with redirects or url rewriting - that way you can send the redirect and the response code ~before~ modx has to process anything [save a bit of overhead]
if you still want to do this in modx, take a peek at the sendRedirect docs & send the correct response code [so google gets the hint that the page has actually moved] Note: the $responseCode option is depreciated and you should use it in the options array these days:
$modx->sendRedirect('http://modx.com',array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
I do agree with not hacking the index.php file, only will cause you grief. What you want to do is place your redirect code in a plugin. Check the Modx API docs for the appropriate event for it to fire on - perhaps: OnWebPageInit will do the trick. Sorry, I don't know exactly which one will work.
HOWEVER ~ IMPORTANT NOTE!
Not all events are actually active, they may show up in the modx manager but don't actually do anything, you will just have to test or dig through the code to find out. [or ask in the community] Again, sorry, I don;t know for sure which ones work and which don't.

introduction for a website

I want to know how to make introduction page which lasts couple seconds and then takes you to the home page of website. That is, when someone types my domain name I need a page to introduce to subject of my website.
This would be what you could use to redirect the site, change the content to the amount of seconds you want the viewer to stay on the page.
<meta http-equiv="refresh" content="0; url=http://whatever.org/">
Referenced from HERE
you can do this in 2 ways,
create a pop up and use javascript setTimeOut() for delay
make index page as your subject of the website and use setTimeOut() for delay and then reidrect to your home page.
You could also use javascript to redirect. This example redirects the page after 2 seconds:
<script type="text/javascript">
function foo()
{
window.location = "http://www.google.com/";
}
setTimeout(foo, 2000);
</script>

Phantom.js fill fields,click submit, and now stuck at accessing the next page

I've start with phantom.js (btw I'm in love). I'm trying to make the headless browser go to my php admin panel, log in with a username and password, and from the page that it redirects to after log in i want to get some text from a div tag.
So far I manage to successfully fill the fields, create a click event, and even find the access to the DOM part of the div tag and get the inner.Text.
The only missing part for me is what to do when phantom.js clicks on a button (the log in button in this case) which will log me in and change the page content. I can't find how to handle after .click(); event.
This is the code I made so far (by the way its a good way to start with...)
var page = new WebPage();
page.open("the url comes here",
function(status){
if(status != "success"){console.log('fail loading the page');}
page.evaluate(function(){
var arr = document.getElementsByName("formname");
arr[0].elements["username"].value="username here";
arr[0].elements["password"].value="password here";
arr[0].elements["submit"].click();
return;
}
phantom.exit()
});
The code i want run on the page that comes after it is
console.log(window.frames[1].document.getElementById('status').innerHTML)
So the only question remaining is how to handle the redirect and launch the script on the other page.
Thanks,
You need to setup a new callback for the page load:
page.onLoadFinished = function(status){
console.log(window.frames[1].document.getElementById('status').innerHTML)
}
this should come right before triggering .click().

Adding <meta> redirect using Greasemonkey

I'm looking to add <meta> element to specific websites using Greasemonkey script. The idea is to redirect the website to another page after X minutes. Something like below:
<META HTTP-EQUIV="Refresh" CONTENT="60; URL=http://example.com">
What is the simplest way to get this done?
You can use Greasemonkey (or JavaScript) to add the meta node, but it won't be parsed (at least in FF 4.0). AFAIK, browsers are only expected to parse meta directives on initial load.
You can use JavaScript to "redirect" the page, after an interval, like so:
setTimeout (function() {
window.location.href = "http://example.com";
},
60000 //-- 60 seconds
);
If you don't want the original page to remain in the browser's history, use:
setTimeout (function() {
window.location.replace ("http://example.com");
},
60000 //-- 60 seconds
);

Resources