0

我正在尝试返回 c= 然后将其写入输入字段并提交值。

var x = window.external.menuArguments.location.href; // IE Get URL Code
alert(x);
// http://site.com/design/page.html?c=235783&p=irol-IRHome

// this code below populates a html pop that is created on popup.
  var parentwin = external.menuArguments; 
  var doc = parentwin.document;
  var sel = doc.selection;
  var rng = sel.createRange();
  var str = new String(rng.text);
  var html = new String(rng.htmlText);
  var ops = "width=650,height=410,status=0,toolbar=0,menubar=0,resizable=1";
  viewSourceWin = parentwin.open("about:blank","viewselectionscr",ops);
  // open document for further output
  viewSourceWin.document.open();
 viewSourceWin.document.write("$(document).ready(function() {");
 viewSourceWin.document.write("load = ?;");
 viewSourceWin.document.write("$('#cmid').val(load);$('.go').click();");
 viewSourceWin.document.write("});");
 viewSourceWin.document.write("<input id='cmid'/><button class='go'>Go</button>")");
4

1 回答 1

1

您想要 location.search,例如:

var query = window.location.search.substring(1);    // use substring to remove the leading '?'
var keyValues = query.split('&');    // split apart
var params = {};
for (var kv in keyValues) {
    var parts = kv.split('=');
    params[ parts[0] ] = parts[1];
}

var c = params['c'];
//... do whatever you need

当然,您还可以使用一个或三个 jquery 插件以及一些更高级的正则表达式。

于 2012-08-06T19:39:46.183 回答