VATarget.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. VATarget = function (w) {
  2. this.window = w ? w : window;
  3. this.clickHandler = jQuery.proxy(this.clickHandler, this);
  4. }
  5. VATarget.prototype = {
  6. active: function () {
  7. var l=this.window.frames.length;
  8. jQuery("A", this.window.document).click(this.clickHandler);
  9. if(l>0){
  10. for(var i=0;i<l;i++){
  11. try{
  12. jQuery("A", this.window.frames[i].document).click(this.clickHandler);
  13. }catch(e){}
  14. }
  15. }
  16. },
  17. clickHandler: function (e) {
  18. e.preventDefault();
  19. var href = jQuery(e.target).attr("href");
  20. if (href) {
  21. if (href.substring(0, 11) == "javascript:") {
  22. this.window.eval(href.substring(11));
  23. return;
  24. }
  25. else if (href.substring(0, 5) == "http:" || href.substring(0, 6) == "https:") {
  26. if (href.indexOf(Host.domain) > -1) {
  27. this.window.document.location.href = href;
  28. }
  29. else {
  30. this.window.open(href, "_blank");
  31. return;
  32. }
  33. }
  34. else if (href.substring(0, 1) == "/") {
  35. href = this.window.document.location.protocol + "//" + this.window.document.location.host + href;
  36. }
  37. else if (href.substring(0, 1) == "#") {
  38. href = this.window.document.location.href + href;
  39. }
  40. else {
  41. var last = this.window.document.location.href.lastIndexOf("/");
  42. if (last > 7) {
  43. href = this.window.document.location.href.substring(0, last + 1) + href;
  44. }
  45. else {
  46. href = this.window.document.location.href + "/" + href;
  47. }
  48. }
  49. this.window.document.location.href = href;
  50. }
  51. }
  52. }