在Javascript中从路径中删除查询字符串的简单方法是什么?我见过一个使用window.location.search的Jquery插件.我不能这样做:在我的情况下,URL是一个从AJAX设置的变量.
var testURL = '/Products/List?SortDirection=dsc&Sort=price&Page=3&Page2=3&SortOrder=dsc'
Run Code Online (Sandbox Code Playgroud) 我postMessage用来将iframe中的事件发送到它的父文档.我控制了双方,但内容来自两个不同的领域.

我的简单问题是,我无法识别其内部回调方法中的iFrame.实现如下:
在iFrame中:
parent.postMessage(JSON.stringify({action: "closeView" }),'*');
Run Code Online (Sandbox Code Playgroud)
在父窗口中:
window.addEventListener('message',function(event) {
if(event.origin !== 'https://example.com')
return;
// Parse message back to json
var messageObject = JSON.parse(event.data);
var source = event.source;
/* this is returning: Window -URL- */
console.log( source );
/* This will throw Permission denied, although this code is inside of "parent" */
console.log(source.parentNode);
},false);
Run Code Online (Sandbox Code Playgroud)
我想识别iframe的某个父元素,它在(逻辑上)在父文档中.
当我尝试event.source.parentNode在所述对象上使用或使用某些jQuery时,Firefox说,我不能这样做以防止XSS,错误:Error: Permission denied to access property 'parentNode'
我怎样才能获得触发postMessage事件监听器的iFrame的父元素?
我正在 WordPress 中编辑表单。我希望我的 jquery 脚本在 url 没有查询字符串时执行。
url 不应该有这样的查询字符串:http : //127.0.0.1/mybetabizopi/login/?action=lostpassword
我只希望我的脚本在 url 是这样或没有查询字符串时运行:http : //127.0.0.1/mybetabizopi/login/
这是我当前的脚本:
var j = jQuery.noConflict();
j(function() {
j('#login #user_login').attr('placeholder', 'Username');
j('#login #user_pass').attr('placeholder', 'Password');
j('#login #user_login').addClass('form-control');
j('#login #user_pass').addClass('form-control');
j('#login #loginform label').wrap( "<div class='input-group'></div>" );
j('#login .form-control').each(function() {
j(this).insertAfter(j(this).parent());
});
j('#loginform .input-group > label').remove();
j('<span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></span>').insertBefore('#user_login');
j('<span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></span>').insertBefore('#user_pass');
});
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。