0

i want to redirect pages from my weblog to a domain which i have on it. for example this url:

the-vampire-diaries.mihanblog.com/post/300

should redirect to this:

tvdfans.ir/post/300

the thing is i only have access to the style codes not the files. i want a JavaScript code that can do this.

Arman Jelodar
  • 95
  • 1
  • 9

2 Answers2

1

You can't write javascript code in stylesheets.

If you have access to an html template, you can just use

<script>
    document.location.hostname = 'example.org';
</script>
Maël Nison
  • 7,055
  • 7
  • 46
  • 77
  • @Derek I've completed the answer with a workaround if 'style' means 'html template' – Maël Nison Jul 15 '12 at 19:06
  • Mael - Actually you can somehow run JavaScript in CSS with hacks: http://stackoverflow.com/questions/476276/using-javascript-in-css ;) – Derek 朕會功夫 Jul 15 '12 at 19:09
  • @Derek True, but it only works on IE, and even this browser has dropped support in the last version :) – Maël Nison Jul 15 '12 at 19:11
  • I was surprised that Firefox also support putting JavaScript in CSS! – Derek 朕會功夫 Jul 15 '12 at 19:12
  • i have access to javascript yes . this script changes the whole address... i want to change the beginning of the url ... for example this: the-vampire-diaries.mihanblog.com/post/300 should change to : tvdfans.ir/post/300 and also this: the-vampire-diaries.mihanblog.com/post/301 should change to : tvdfans.ir/post/301 not only the first page of site – Arman Jelodar Jul 16 '12 at 13:40
  • @ArmanJelodar Have you tried my script ? I've test it on IE9, firefox and chrome, and it works as specified. Please notice that the variable which is modified is `document.location.hostname` and not the full `document.location`. – Maël Nison Jul 16 '12 at 21:24
0

Yes you can achieve this using javascript

**Example:**
<script langauge="text/javascript">
window.location.replace(someUrl");
</script>
HatSoft
  • 11,077
  • 3
  • 28
  • 43
  • this script changes the whole address... i want to change the beginning of the url ... for example this: the-vampire-diaries.mihanblog.com/post/300 should change to : tvdfans.ir/post/300 and also this: the-vampire-diaries.mihanblog.com/post/301 should change to : tvdfans.ir/post/301 not only the first page of site – Arman Jelodar Jul 16 '12 at 13:38